<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>jquery.localtime test script</title>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
	<script type="text/javascript" src="jquery.localtime.js"></script>
	<script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script>
	<link rel="stylesheet" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css" type="text/css" media="screen" />

	<script type="text/javascript">
		$(document).ready(function(){
    
			module( "Limited ISO 8601 parsing" );
			
			test("Parse no seconds", function() {
				deepEqual( new Date( Date.UTC(2011,0,3,13,39,0,0) ), $.localtime.parseISOTimeString("2011-01-03 13:39Z"), "No seconds present" );
			});
			test("Parse with seconds", function() {
				deepEqual( new Date( Date.UTC(2011,0,3,13,39,30,0) ), $.localtime.parseISOTimeString("2011-01-03 13:39:30Z"), "Seconds only present" );
			});
			test("Parse with milliseconds", function() {
				deepEqual( new Date( Date.UTC(2011,0,3,13,39,30,300) ), $.localtime.parseISOTimeString("2011-01-03 13:39:30.300Z"), "Milliseconds present" );
			});
			test("Parse with milliseconds and space", function() {
				deepEqual( new Date( Date.UTC(2011,0,3,13,39,30,300) ), $.localtime.parseISOTimeString("  2011-01-03 13:39:30.300Z  "), "Milliseconds and spaces present" );
			});
			test("Parse with milliseconds and whitespace", function() {
				deepEqual( new Date( Date.UTC(2011,0,3,13,39,30,300) ), $.localtime.parseISOTimeString("\n2011-01-03 13:39:30.300Z\n"), "Milliseconds and whitespace present" );
			});
			test("Bad length", function() {
				raises( function() { $.localtime.parseISOTimeString("foobar"), "Invalid length" } );
			});
			test("Bad year", function() {
				raises( function() { $.localtime.parseISOTimeString("YYYY-01-03 13:39:30.300Z"), "Invalid year" } );
			});
			test("Bad month", function() {
				raises( function() { $.localtime.parseISOTimeString("2011-MM-03 13:39:30.300Z"), "Invalid month" } );
				raises( function() { $.localtime.parseISOTimeString("2011-13-03 13:39:30.300Z"), "Invalid month - too large" } );
			});
			test("Bad day", function() {
				raises( function() { $.localtime.parseISOTimeString("2011-01-dd 13:39:30.300Z"), "Invalid day" } );
				raises( function() { $.localtime.parseISOTimeString("2011-01-32 13:39:30.300Z"), "Invalid day - too large" } );
			});
			test("Bad minute", function() {
				raises( function() { $.localtime.parseISOTimeString("2011-01-03 13:hh:30.300Z"), "Invalid hour" } );
				raises( function() { $.localtime.parseISOTimeString("2011-01-03 13:61:30.300Z"), "Invalid hour - too large" } );
			});
			test("Bad hour", function() {
				raises( function() { $.localtime.parseISOTimeString("2011-01-03 13:39:mm.300Z"), "Invalid minute" } );
				raises( function() { $.localtime.parseISOTimeString("2011-01-03 13:39:61.300Z"), "Invalid minute - too large" } );
			});
			test("Bad millisecond", function() {
				raises( function() { $.localtime.parseISOTimeString("2011-01-03 13:39:30.sssZ"), "Invalid millisecond" } );
			});
		
			module("Date/time formats");
			test("Day formats", function() {
				$.localtime.setFormat("d");
				equals("3", $.localtime.toUTCTime("2011-01-03 13:39:30.300Z") );
				$.localtime.setFormat("dd");
				equals("03", $.localtime.toUTCTime("2011-01-03 13:39:30.300Z") );
			});
			test("Month formats", function() {
				$.localtime.setFormat("M");
				equals("1", $.localtime.toUTCTime("2011-01-03 13:39:30.300Z") );
				$.localtime.setFormat("MM");
				equals("01", $.localtime.toUTCTime("2011-01-03 13:39:30.300Z") );
				$.localtime.setFormat("MMM");
				equals("Jan", $.localtime.toUTCTime("2011-01-03 13:39:30.300Z") );
				equals("Feb", $.localtime.toUTCTime("2011-02-03 13:39:30.300Z") );
				equals("Mar", $.localtime.toUTCTime("2011-03-03 13:39:30.300Z") );
				equals("Apr", $.localtime.toUTCTime("2011-04-03 13:39:30.300Z") );
				equals("May", $.localtime.toUTCTime("2011-05-03 13:39:30.300Z") );
				equals("Jun", $.localtime.toUTCTime("2011-06-03 13:39:30.300Z") );
				equals("Jul", $.localtime.toUTCTime("2011-07-03 13:39:30.300Z") );
				equals("Aug", $.localtime.toUTCTime("2011-08-03 13:39:30.300Z") );
				equals("Sep", $.localtime.toUTCTime("2011-09-03 13:39:30.300Z") );
				equals("Oct", $.localtime.toUTCTime("2011-10-03 13:39:30.300Z") );
				equals("Nov", $.localtime.toUTCTime("2011-11-03 13:39:30.300Z") );
				equals("Dec", $.localtime.toUTCTime("2011-12-03 13:39:30.300Z") );
				$.localtime.setFormat("MMMMM");
				equals("January", $.localtime.toUTCTime("2011-01-03 13:39:30.300Z") );
				equals("February", $.localtime.toUTCTime("2011-02-03 13:39:30.300Z") );
				equals("March", $.localtime.toUTCTime("2011-03-03 13:39:30.300Z") );
				equals("April", $.localtime.toUTCTime("2011-04-03 13:39:30.300Z") );
				equals("May", $.localtime.toUTCTime("2011-05-03 13:39:30.300Z") );
				equals("June", $.localtime.toUTCTime("2011-06-03 13:39:30.300Z") );
				equals("July", $.localtime.toUTCTime("2011-07-03 13:39:30.300Z") );
				equals("August", $.localtime.toUTCTime("2011-08-03 13:39:30.300Z") );
				equals("September", $.localtime.toUTCTime("2011-09-03 13:39:30.300Z") );
				equals("October", $.localtime.toUTCTime("2011-10-03 13:39:30.300Z") );
				equals("November", $.localtime.toUTCTime("2011-11-03 13:39:30.300Z") );
				equals("December", $.localtime.toUTCTime("2011-12-03 13:39:30.300Z") );
			});
			test("Year formats", function() {
				$.localtime.setFormat("yy");
				equals("11", $.localtime.toUTCTime("2011-01-03 13:39:30.300Z") );
				$.localtime.setFormat("yyyy");
				equals("2011", $.localtime.toUTCTime("2011-01-03 13:39:30.300Z") );
			});
			test("Hour formats", function() {
				$.localtime.setFormat("H");
				equals("3", $.localtime.toUTCTime("2011-01-03 03:39:30.300Z") );
				$.localtime.setFormat("HH");
				equals("03", $.localtime.toUTCTime("2011-01-03 03:39:30.300Z") );
			});
			test("Minute formats", function() {
				$.localtime.setFormat("m");
				equals("3", $.localtime.toUTCTime("2011-01-03 13:03:30.300Z") );
				$.localtime.setFormat("mm");
				equals("03", $.localtime.toUTCTime("2011-01-03 13:03:30.300Z") );
			});
			test("Second formats", function() {
				$.localtime.setFormat("s");
				equals("3", $.localtime.toUTCTime("2011-01-03 13:39:03.300Z") );
				$.localtime.setFormat("ss");
				equals("03", $.localtime.toUTCTime("2011-01-03 13:39:03.300Z") );
			});
			test("Millisecond formats", function() {
				$.localtime.setFormat("S");
				equals("3", $.localtime.toUTCTime("2011-01-03 13:39:30.003Z") );
				$.localtime.setFormat("SS");
				equals("03", $.localtime.toUTCTime("2011-01-03 13:39:30.003Z") );
				$.localtime.setFormat("SSS");
				equals("003", $.localtime.toUTCTime("2011-01-03 13:39:30.003Z") );
			});
			test("Timezone offset formats", function() {
				$.localtime.setFormat("z");
				equals("+0", $.localtime.toUTCTime("2011-01-03 13:39:30.003Z") );
				$.localtime.setFormat("zz");
				equals("+00", $.localtime.toUTCTime("2011-01-03 13:39:30.003Z") );
				$.localtime.setFormat("zzz");
				equals("+00:00", $.localtime.toUTCTime("2011-01-03 13:39:30.003Z") );
			});
			test("12 hr format", function() {
				$.localtime.setFormat("h");
				equals("3", $.localtime.toUTCTime("2011-01-03 03:39:30.003Z") );
				equals("11", $.localtime.toUTCTime("2011-01-03 23:39:30.003Z") );
				equals("12", $.localtime.toUTCTime("2011-01-03 00:39:30.003Z") );
				equals("3", $.localtime.toUTCTime("2011-01-03 03:39:30.003Z") );
				equals("11", $.localtime.toUTCTime("2011-01-03 11:39:30.003Z") );
				equals("12", $.localtime.toUTCTime("2011-01-03 12:39:30.003Z") );
				equals("1", $.localtime.toUTCTime("2011-01-03 13:39:30.003Z") );
				$.localtime.setFormat("hh");
				equals("03", $.localtime.toUTCTime("2011-01-03 03:39:30.003Z") );
				equals("11", $.localtime.toUTCTime("2011-01-03 23:39:30.003Z") );
				equals("12", $.localtime.toUTCTime("2011-01-03 00:39:30.003Z") );
				equals("03", $.localtime.toUTCTime("2011-01-03 03:39:30.003Z") );
				equals("11", $.localtime.toUTCTime("2011-01-03 11:39:30.003Z") );
				equals("12", $.localtime.toUTCTime("2011-01-03 12:39:30.003Z") );
				equals("01", $.localtime.toUTCTime("2011-01-03 13:39:30.003Z") );
			});
			test("AM/PM format 1", function() {
				$.localtime.setFormat("a");
				equals("AM", $.localtime.toUTCTime("2011-01-03 08:39:30.003Z") );
				equals("PM", $.localtime.toUTCTime("2011-01-03 16:39:30.003Z") );
			});
			test("AM/PM format 2", function() {
				$.localtime.setFormat("t");
				equals("A", $.localtime.toUTCTime("2011-01-03 08:39:30.003Z") );
				equals("P", $.localtime.toUTCTime("2011-01-03 16:39:30.003Z") );
				$.localtime.setFormat("tt");
				equals("AM", $.localtime.toUTCTime("2011-01-03 08:39:30.003Z") );
				equals("PM", $.localtime.toUTCTime("2011-01-03 16:39:30.003Z") );
			});
		});
	</script>
  
</head>
<body>
	<h1 id="qunit-header">jquery.localtime test script</h1>
	<h2 id="qunit-banner"></h2>
	<div id="qunit-testrunner-toolbar"></div>
	<h2 id="qunit-userAgent"></h2>
	<ol id="qunit-tests"></ol>
	<div id="qunit-fixture">test markup, will be hidden</div>
</body>
</html>

